<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentBlockUser.class.php, $Author:  $ */



/** Block user component
 * 
 * Parameters:
 *  1. oBlocker (required)- user (current) who block another user
 *  2. oUser (required) - user who will be blocked
 * 
 * @package module.account
 * @version $Id: PhpFox_ComponentBlockUser.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Account_ComponentBlockUser extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oUser = $this->getParam('oUser');
	    /* @var $oAcc PhpFox_Mod_Account_ItemAccount */
	    assert($oUser != null); //user
	    
	    $oBlocker = $this->getParam('oBlocker');
	    /* @var $oAcc PhpFox_Mod_Account_ItemAccount */
	    assert($oBlocker != null); //blocker
	    
	    $oReq = &App::getRequest();
    
        $oSrvBlock = $this->_oModule->getService('Block');
        /* @var $oSrvBlock PhpFox_Mod_Account_ServiceBlock */
        
        $oSrvSec = $this->_oModule->getService('Security');
        /* @var $oSrvSec PhpFox_Mod_Account_ServiceSecurity */
        
        if (! $oSrvSec->isStaff())
        {
            $aBlockerMemb = $oSrvSec->getUserMembershipData($oBlocker);
            if ( ! $aBlockerMemb['allow_block'])
            {
                App::gotoUrl('public.denied');
            }
        }
        
	    // processing
        switch($oReq->getAction())
        {
            case 'block_user':
                $oSrvBlock->block($oBlocker, $oUser);
                $oUrl = &App::getUrl();
                $oUrl->setParam('act', 'blocked');
                App::forward($oUrl->getUrl());
				break;
				
            case 'unblock_user':
                $oSrvBlock->unblock($oBlocker, $oUser);
                $oUrl = &App::getUrl();
                $oUrl->setParam('act', 'unblocked');
                App::forward($oUrl->getUrl());
                break;
        }
	    
                              
		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assignSrc(array(
		    'aUser'    => $oUser->aData,
		    'aBlocker' => $oBlocker->aData,
    		'sAction'  => $oReq->getAction(),
		));
		$srcHtml = $oTpl->fetch('BlockUser.html');
		return $srcHtml;
	}

}
?>